<template>
	<view>
		<!-- 店铺信息 -->
		<uni-card>
			<view class="card">
				<!-- 店铺图片 -->
				<view class="card-pic">
					<image class="card-image" :src="storeInfo.logo"></image>
				</view>
				<view class="card-content">
					<!-- 店铺名字 -->
					<text class="black-color big">{{storeInfo.name}}</text>
					<!-- 店铺评分、销量 -->
					<view class="card-info">
						<text class="store-score red-color">{{storeInfo.score}} 分</text>
					</view>
					<!-- 店铺标签 -->
					<view class="store-tag">
						<text class="tag small green-color" v-if="storeInfo.bread_type">烘焙</text>
						<text class="tag small green-color" v-if="storeInfo.drink_type">饮品</text>
						<text class="tag small green-color" v-if="storeInfo.meal_type">简餐</text>
					</view>
				</view>
			</view>
			<!-- 店铺地址 -->
			<view class="store-address">
				<u-icon name="map" color="#296844" class="store-icon" size="18"></u-icon>
				<text class="middle">{{storeInfo.address}}</text>
			</view>
			<!-- 店铺电话 -->
			<view class="store-tel">
				<u-icon name="phone" color="#296844" class="store-icon" size="18"></u-icon>
				<text class="middle">{{storeInfo.tel}}</text>
			</view>
		</uni-card>

		<!-- 商品信息 -->
		<view class="good" v-for="(item,index) in goodList">
			<uni-card>
				<view class="card">
					<!-- 商品图片 -->
					<view class="card-pic">
						<image class="good-image" :src="item.logo"></image>
					</view>
					<view class="card-content">
						<!-- 商品名字 -->
						<text class="big black-color">{{item.name}}</text>
						<!-- 商品销量 -->
						<view>
							<text class="middle">月销 {{item.month_sale}}</text>
						</view>
						<!-- 取袋时间 -->
						<view>
							<text class="middle">取袋时间: {{item.start_time}}-{{item.end_time}}</text>
						</view>
						<view class="last">
							<!-- 商品价格 -->
							<view>
								<text class="red-color">￥</text>
								<text class="big red-color">{{item.price}}</text>
							</view>
							<!-- 购买按钮 -->
							<view>
								<button class="buy-btn middle" type="default" size="mini"
									@click="buy($event,index)">立即购买</button>
							</view>

						</view>
					</view>
				</view>
			</uni-card>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				storeInfo: '',
				goodList: '',
			}
		},
		onLoad(option) {
			//option为object类型，会序列化上个页面传递的参数
			uniCloud.callFunction({
					name: 'getStore',
					data: {
						'_id': option.store_id,
					}
				})
				.then(res => {
					this.storeInfo = res.result.data[0];
				})
				.catch(error => {
					console.log(error);
				});
			uniCloud.callFunction({
					name: 'getGood',
					data: {
						'store_id': option.store_id,
					}
				})
				.then(res => {
					this.goodList = res.result.data;
				})
				.catch(error => {
					console.log(error);
				});
		},
		methods: {
			buy(e, index) {
				uni.navigateTo({
					url: './buy?store_id=' + this.storeInfo._id + '&good_id=' + this.goodList[index]._id
				});
			}
		}
	}
</script>

<style>
	.small {
		font-size: 20rpx;
	}

	.middle {
		font-size: 25rpx;
	}

	.big {
		font-size: 30rpx;
		font-weight: bold;
	}

	.green-color {
		color: #296844;
	}

	.black-color {
		color: black;
	}

	.red-color {
		color: brown;
	}

	.card {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.card-pic {
		flex: 2;
	}

	.card-image {
		display: block;
		margin: 0 auto;
		width: 60px;
		height: 60px;
		border-radius: 5px;
	}
	.good-image {
		display: block;
		margin: 0 auto;
		width: 90px;
		height: 90px;
		border-radius: 5px;
	}

	.card-content {
		flex: 8;
		margin-left: 20rpx;
	}

	.card-info {
		display: flex;
		justify-content: space-between;
		margin: 5rpx 0;
	}

	.store-icon {
		margin-right: 5px;
		width: 15px;
		height: 15px;
	}

	.store-address {
		display: flex;
		align-items: center;
		flex-direction: row;
		margin-top: 15rpx;
		margin-bottom: 5rpx;
		word-break: break-all;
	}

	.store-tel {
		display: flex;
		align-items: center;
		flex-direction: row;
		margin-bottom: 5rpx;
	}

	.store-tag {
		display: flex;
		flex-direction: row;
	}

	.tag {
		width: 80rpx;
		height: 35rpx;
		border: 1px solid #296844;
		border-radius: 20rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-right: 15rpx;
	}

	.last {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.buy-btn {
		border: 1px solid #296844;
		border-radius: 10px;
		background-color: rgba(123, 197, 111, 0.7);
	}
</style>